package com.wiley.homePO;

import io.appium.java_client.android.AndroidDriver;

import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;

import com.wiley.publicMethod.BasePage;
import com.wiley.publicMethod.LoggerControler;

import java.io.IOException;
import java.net.MalformedURLException;

public class HotAlbumPage extends BasePage {
	
	LoggerControler log;

	/**
	 * 页面元素
	 */
	//热门专辑
	public static final By hot_album_name_loc = By.name("热门专辑");
	
	//专辑列表封面cover
	public static final By hot_album_cover_loc = By.id(BaseId + "cover");
	
	//专辑title
	public static final By hot_album_titel_loc = By.id(BaseId + "title");

	//某一专辑列表image
	public static final By hot_album_image_loc = By.id(BaseId + "image");
	
	//详情页面title
	public static final By hot_album_titel_tv_loc = By.id(BaseId + "title_tv");
	
	//返回上一级
	public static final By hot_album_back_loc = By.name("转到上一层级");
	
	/**
	 * 操作方法
	 */
	//点击热门专辑
	public void clickHotAlbum(){
		this.clickEle(hot_album_name_loc);
	}
	
	//点击某一专辑cover
	public void clickAlbumCover(int i){
		this.clickEles(hot_album_cover_loc, i);
	}
	
	//获取专辑菜谱名
	public String getAlbumName(){
		WebElement ele = this.findEle(hot_album_titel_loc);
		return ele.getText();
	}
	
	//循环访问专辑及其image
	public void clickAlbumCoverAndImage(){
		int coverSize = this.getElesLength(hot_album_cover_loc);
		for(int i = 0; i < coverSize; i++){
			this.clickEles(hot_album_cover_loc, i);
			log.info("该专辑名为："+this.getAlbumName());
			int imageSize = this.getElesLength(hot_album_image_loc);
			for(int j = 1; j < imageSize; j++){
				this.clickEles(hot_album_image_loc, j);
				log.info("该recipe名为："+this.getAlbumRecipeName());
				driver.sendKeyEvent(4);
			}
			this.clickEle(hot_album_back_loc);
		}
	}

	//获取专辑菜谱名
	public String getAlbumRecipeName(){
		WebElement ele = this.findEle(hot_album_titel_tv_loc);
		return ele.getText();
	}
	/**
	 * 业务封装
	 * @throws MalformedURLException 
	 */
	public void hotAlbumView(Class name) throws MalformedURLException  {
		log = this.MyLogger(name);
		AndroidDriver driver = super.SetDriver();
		this.clickHotAlbum();
		log.info("点击进入热门专辑列表");
		this.clickAlbumCoverAndImage();
		log.info("该case测试通过！");
	}
}
